home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / ms_sh22b.zip / src / showkey.c < prev    next >
C/C++ Source or Header  |  1993-12-01  |  3KB  |  152 lines

  1. /* MS-DOS SHELL - Show Scan codes
  2.  *
  3.  * MS-DOS SHELL - Copyright (c) 1990,1,2 Data Logic Limited.
  4.  *
  5.  * This code is subject to the following copyright restrictions:
  6.  *
  7.  * 1.  Redistribution and use in source and binary forms are permitted
  8.  *     provided that the above copyright notice is duplicated in the
  9.  *     source form and the copyright notice in file sh6.c is displayed
  10.  *     on entry to the program.
  11.  *
  12.  * 2.  The sources (or parts thereof) or objects generated from the sources
  13.  *     (or parts of sources) cannot be sold under any circumstances.
  14.  *
  15.  *    $Header: /usr/users/istewart/src/shell/sh2.2/RCS/showkey.c,v 2.2 1993/06/14 10:59:58 istewart Exp $
  16.  *
  17.  *    $Log: showkey.c,v $
  18.  * Revision 2.2  1993/06/14  10:59:58  istewart
  19.  * More changes for 223 beta
  20.  *
  21.  * Revision 2.1  1993/06/02  09:54:34  istewart
  22.  * Beta 223 Updates - see Notes file
  23.  *
  24.  * Revision 2.0  1992/07/16  14:35:08  istewart
  25.  * Release 2.0
  26.  *
  27.  *
  28.  */
  29.  
  30. #include <stdio.h>
  31. #include <unistd.h>
  32. #include <ctype.h>
  33.  
  34. #if defined (OS2) || defined (__OS2__)
  35. #  define INCL_KBD
  36. #  include <os2.h>
  37.  
  38. #  if defined (__OS2__)
  39. #    include <bsedev.h>
  40. #  endif
  41.  
  42. #else
  43. #  include <dos.h>
  44. #endif
  45.  
  46. void main (void)
  47. {
  48. #if defined (OS2) || defined (__OS2__)
  49.     KBDKEYINFO        kbci;
  50. #else
  51.     union REGS    Key;
  52.     union REGS    Shift;
  53. #endif
  54.  
  55.     puts ("Control C to terminate");
  56.  
  57.     while (TRUE)
  58.     {
  59. #if defined (OS2) || defined (__OS2__)
  60.  
  61.     KbdCharIn (&kbci, IO_WAIT, 0);
  62.  
  63.     printf ("Scan = 0x%.4x ", kbci.chScan);
  64.     printf ("ASCII = 0x%.4x (%c) ", kbci.chChar, isprint (kbci.chChar) ?
  65.         kbci.chChar : '.');
  66.  
  67.     printf ("Shift = 0x%.4x ( ", kbci.fsState);
  68.  
  69.     if (kbci.fsState & RIGHTSHIFT)
  70.         printf ("RIGHTSHIFT ");
  71.  
  72.     if (kbci.fsState & LEFTSHIFT)
  73.         printf ("LEFTSHIFT ");
  74.  
  75.     if (kbci.fsState & ALT)
  76.         printf ("ALT ");
  77.  
  78.     if (kbci.fsState & LEFTALT)
  79.         printf ("LEFTALT ");
  80.  
  81.     if (kbci.fsState & RIGHTALT)
  82.         printf ("RIGHTALT ");
  83.  
  84.     if (kbci.fsState & CONTROL)
  85.         printf ("CONTROL ");
  86.  
  87.     if (kbci.fsState & LEFTCONTROL)
  88.         printf ("LEFTCONTROL ");
  89.  
  90.     if (kbci.fsState & RIGHTCONTROL)
  91.         printf ("RIGHTCONTROL ");
  92.  
  93.     if (kbci.fsState & SCROLLLOCK_ON)
  94.         printf ("SCROLLLOCK_ON ");
  95.  
  96.     if (kbci.fsState & SCROLLLOCK)
  97.         printf ("SCROLLLOCK ");
  98.  
  99.     if (kbci.fsState & NUMLOCK_ON)
  100.         printf ("NUMLOCK_ON ");
  101.  
  102.     if (kbci.fsState & NUMLOCK)
  103.         printf ("NUMLOCK ");
  104.  
  105.     if (kbci.fsState & CAPSLOCK_ON)
  106.         printf ("CAPSLOCK_ON ");
  107.  
  108.     if (kbci.fsState & CAPSLOCK)
  109.         printf ("CAPSLOCK ");
  110.  
  111.     if (kbci.fsState & INSERT_ON)
  112.         printf ("INSERT_ON ");
  113.  
  114.     if (kbci.fsState & SYSREQ)
  115.         printf ("SYSREQ ");
  116.  
  117.     puts (")");
  118.  
  119.     if (kbci.chChar == 0x03)
  120.         exit (0);
  121. #else
  122.     Key.x.ax = 0;
  123.     int86 (0x16, &Key, &Key);
  124.  
  125.     Shift.x.ax = 0x0200;
  126.     int86 (0x16, &Shift, &Shift);
  127.  
  128.     printf ("Scan = 0x%.4x ", Key.h.ah);
  129.     printf ("ASCII = 0x%.4x (%c) ", Key.h.al, isprint (Key.h.al) ?
  130.         Key.h.al : '.');
  131.     printf ("Shift = 0x%.4x ( ", Shift.h.al);
  132.  
  133.     if (Shift.h.al & 0x01)
  134.         printf ("Right Shift ");
  135.  
  136.     if (Shift.h.al & 0x02)
  137.         printf ("Left Shift ");
  138.  
  139.     if (Shift.h.al & 0x04)
  140.         printf ("Control ");
  141.  
  142.     if (Shift.h.al & 0x08)
  143.         printf ("Alt ");
  144.  
  145.     puts (")");
  146.  
  147.     if (Key.h.al == 0x03)
  148.         exit (0);
  149. #endif
  150.     }
  151. }
  152.